<?php
namespace Admin\Controller;

class UserController extends MyController {
    public function index(){


        $count      = M('user')->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $user_list = M('user')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('user_list', $user_list);
        $this->assign('page',$show);// 赋值分页输出



        $this->display('index');
    }
    public function add() {
        $tbl_user = M('user');
        if (IS_POST) {
            $user_name = I('post.user_name','');
            $user_zhi = I('post.user_zhi','');
            $user_decrbit = I('post.user_decrbit','');

            $data = array();
            $data['user_name'] = $user_name;
            $data['user_zhi'] = $user_zhi;
            $data['user_decrbit'] = $user_decrbit;
            $tbl_user->add($data);
            echo json_encode(array('msg' => '成功','data' =>$_POST));
            exit;
        }
        $this->display('add');
    }
}